import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver, VueUseComponentsResolver } from 'unplugin-vue-components/resolvers'

export default function autoImport() {
  return [
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        {
          '@/hooks/element/useEleMessage': [['*', 'DuMessage']],
        },
      ],
      // 解析器，例如element-plus的ElementPlusResolver
      resolvers: [ElementPlusResolver()],

      // 解决自动引入后的eslint报错
      eslintrc: {
        enabled: false, // 先写成true，生成文件后再改成false
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
    }),
    Components({
      resolvers: [
        ElementPlusResolver({ importStyle: 'sass' }), //element-plus组件按需导入// 自动引入修改主题色添加这一行，使用预处理样式
        VueUseComponentsResolver(), // vueuse但需导入
      ],
      extensions: ['vue'],
      dirs: ['src/components'], // 自动引入组件
      directoryAsNamespace: true, // 组件名称包含目录，防止同名组件冲突
    }),
  ]
}
